var $message = $("#message");

//ajax登录
function loginByAjax(userName, password) {

  $.ajax({
    url: "/bank/subLogin",
    data: {"userName": userName, "password": password},
    dataType: "json",
    type: "post",
    // timeout:5000,
    beforeSend: beforeSend,
    success: callBack,
    error: errorBack
  });

  function callBack(data) {
    console.log(data);
    if (data.code == 200) {
      window.location.href = "/index";
    } else {
      $message.text("登录失败，用户名或密码错误");
      $("#submit").removeAttr("disabled").css("backgroundColor", "dodgerblue").val("登录");
    }
  }

  function errorBack() {
    $("#submit").removeAttr("disabled").css("backgroundColor", "dodgerblue").val("登录");
    alert("登录失败，请求超时");
  }

  function beforeSend() {
    $("#submit").attr("disabled", "true").css("backgroundColor", "deepSkyblue").val("登录中...");
  }
}